﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Xml;
    using WMS6.Web.CommonMethodServiceRef;

    public class About : BasePage
    {
        protected HtmlForm form1;
        protected Label lblAppVersion;
        protected Label lblAuthorisedUserNum;
        protected Label lblAuthorisedWHNum;
        protected Label lblCompany;
        protected Label lblDBVersion;
        protected Label lblExpiryDate;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;

        protected void Page_Load(object sender, EventArgs e)
        {
            base.InitPage(this.Page);
            this.SetAppSettingInfo2From();
            this.Page.Response.Buffer = false;
            this.Page.Response.Cache.SetNoStore();
        }

        private void SetAppSettingInfo2From()
        {
            List<AppSettingInfo> appSettingInfos = CommoneMethodServiceClientProxy.GetInstance().GetAllAppSettingInfo();
            if ((appSettingInfos != null) && (appSettingInfos.Count > 0))
            {
                this.lblAppVersion.Text = appSettingInfos[0].Value;
                this.lblAuthorisedUserNum.Text = appSettingInfos[1].Value;
                this.lblAuthorisedWHNum.Text = appSettingInfos[2].Value;
                this.lblCompany.Text = appSettingInfos[3].Value;
                this.lblDBVersion.Text = appSettingInfos[4].Value;
            }
            XmlDocument doc = new XmlDocument();
            XmlNodeReader reader = null;
            string s = string.Empty;
            try
            {
                string xmlPath = base.Server.MapPath("") + @"\License\license.qt";
                if (File.Exists(xmlPath))
                {
                    string xmlString = string.Empty;
                    using (StreamReader sr = new StreamReader(xmlPath))
                    {
                        xmlString = EnDeCrypt.DecryptString(sr.ReadToEnd());
                    }
                    doc.LoadXml(xmlString);
                    reader = new XmlNodeReader(doc);
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:
                                s = reader.Name;
                                goto Label_01E2;

                            case XmlNodeType.Text:
                                if (string.Compare(s, "MaxUsers", true) != 0)
                                {
                                    break;
                                }
                                this.lblAuthorisedUserNum.Text = reader.Value;
                                goto Label_01E2;

                            default:
                                goto Label_01E2;
                        }
                        if (string.Compare(s, "Warehouses", true) == 0)
                        {
                            this.lblAuthorisedWHNum.Text = reader.Value;
                        }
                        else if (string.Compare(s, "Expired", true) == 0)
                        {
                            this.lblExpiryDate.Text = reader.Value;
                        }
                    Label_01E2:;
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
    }
}

